package com.zzz.java8;

import java.util.function.DoubleFunction;
import java.util.function.Function;

/**
 * @author zhuzhizun
 * @date 2021/8/11
 */
public class FunctionTest {


    public static double integrate(DoubleFunction<Double> f, double a, double b) {
        return (f.apply(a) + f.apply(b)) * (b - a) / 2.0;
    }


    public static void main(String[] args) {

        double result = integrate((double x) -> x + 10, 3, 7);
        System.out.println(result);


        Function<Integer, Integer> plus = x -> x + 1;
        Function<Integer, Integer> multiply = x -> x * 2;
        Function<Integer, Integer> combination1 = plus.andThen(multiply);
        Function<Integer, Integer> combination2 = plus.compose(multiply);

        // 16 (5+1)*2
        System.out.println(combination1.apply(5));
        //11  5*2+1
        System.out.println(combination2.apply(5));
    }
}
